const mysqlPool = require('../configs/mysqlpool');

class UserModel {

    /**
     * 获取项目列表长度
     * @param {*} params 
     */
    static countPmlist(params) {
        let _sql = `SELECT COUNT(*) as total FROM pmList ${params.status_sql};`
        console.log(_sql);
        return mysqlPool.query(_sql)
    }

    /**
     * 获取项目列表
     * @param {*} params 
     */
    static getPmList(params) {
        let _sql = `SELECT ${params.keys} FROM pmlist ${params.status_sql} LIMIT ${params.start}, ${params.size};`
        console.log(_sql);
        return mysqlPool.query(_sql)
    }

    /**
     * 获取项目详情
     * @param {*} id 
     */
    static getPmDetail(id) {
        let _sql = `select * FROM pmList where id="${id}";`
        return mysqlPool.query(_sql)
    }

    /**
     * 添加项目
     * @param {*} keys 字段名
     * @param {*} values 对应的字段值
     */
    static adPmData(params) {
        let _sql = `INSERT INTO pmlist (${params.keys}) VALUES (${params.values});`
        console.log(_sql)
        return mysqlPool.query(_sql);
    }

    /**
     * 更新项目
     * @param {*} params
     */
    static updatePmData(params) {
        let _sql = `UPDATE pmlist ${params.updateSql} where id=${params.id};`
        console.log(_sql);
        return mysqlPool.query(_sql);
    }
}

module.exports = UserModel;